package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.CancelsetsessionsilentBean;
import com.ymatou.iapi.im.parameter.SendMessageToBuyerBean;
import com.ymatou.iapi.im.parameter.SendMessageToSellerBean;
import com.ymatou.iapi.im.service.CancelsetsessionsilentCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.Map;

/**
*取消会话免打扰
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Cancelsetsessionsilent{
	private static CancelsetsessionsilentBean cancelsetsessionsilentBean;
	private static CancelsetsessionsilentCall cancelsetsessionsilentCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消会话免打扰");
	}

	@Before
	public void caseUp() {
		cancelsetsessionsilentBean=new CancelsetsessionsilentBean();
		cancelsetsessionsilentCall=new CancelsetsessionsilentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelsetsessionsilentCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Cancelsetsessionsilent_01() {
		Logger.start(true,"取消会话免打扰");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int fromUserId = 24635724;
			SendMessageToBuyerBean sendMessageToBuyerBean = ImCallService.initSendMessageToBuyerBean(fromUserId,userId,"你好");
			ImCallService.SendMessageToBuyer(sendMessageToBuyerBean);
			ImCallService.SetSessionSilent(fromUserId,userId);

			Map map = new ImDefaultWapper().selectTotalCount(userId,fromUserId).get(0);
			Logger.verifyEquals(1,Integer.parseInt(map.get("Slient").toString()),"验证是否设置免打扰");
			cancelsetsessionsilentBean.setFromUserId(fromUserId);
			cancelsetsessionsilentBean.setToUserId(userId);
			cancelsetsessionsilentCall.setData(cancelsetsessionsilentBean);
			cancelsetsessionsilentCall.callService();
			Map map1 = new ImDefaultWapper().selectTotalCount(userId,fromUserId).get(0);
			Logger.verifyEquals(0,Integer.parseInt(map1.get("Slient").toString()),"验证是否设置免打扰");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}